import sys
import enrol

commands = sys.argv
en = enrol.Enrol(".\\data\\")
if len(commands) == 1:
    print "Subjects are:"
    for subjectCode in en.subjects():
        subjectName = en.subjectName(subjectCode)
        if subjectName == None:
            continue
        classCount = 0
        studentCount = 0
        for classID in en.classes(subjectCode):
            classCount = classCount + 1
            try:
                classInfo = en.classInfo(classID)
                studentCount = studentCount + len(classInfo[4])
            except KeyError:
                continue
        print "%s \t %s \t classes: %d \t students: %s"%(subjectCode, subjectName, classCount, studentCount)

elif len(commands) == 3:
    if commands[1] != "--student":
        print "usage: %s [--student (studentID)]"%commands[0]
        sys.exit(0)
    
    studentID = commands[2]
    for classID in en.checkStudent(studentID):
        try:
            classInfo = en.classInfo(classID)
            subjectName = en.subjectName(classInfo[0])
            print "%s \t (%s),%s, in %s"%(classInfo[0], subjectName, classInfo[1], classInfo[2])
        except KeyError:
            continue

else:
    print "usage: %s [--student (studentID)]"%commands[0]